#ifndef OPERATIONS_ORDER_H
#define OPERATIONS_ORDER_H

#include <QWidget>
#include <QJsonObject>
#include "api.h"

namespace Ui {
class operations_order;
}

class operations_order : public QWidget
{
    Q_OBJECT

public:
    explicit operations_order(QWidget *parent = nullptr);
    ~operations_order();

private slots:
    void on_searchButton_clicked();
    void on_refreshButton_clicked();
    void on_statusComboBox_currentTextChanged(const QString &text);
    void on_dateComboBox_currentTextChanged(const QString &text);
    void on_typeComboBox_currentTextChanged(const QString &text);
    void on_firstPageBtn_clicked();
    void on_prevPageBtn_clicked();
    void on_nextPageBtn_clicked();
    void on_lastPageBtn_clicked();

private:
    Ui::operations_order *ui;
    Api* m_api;
    
    // 分页相关
    int currentPage = 1;
    int totalPages = 1;
    int recordsPerPage = 10;
    int totalRecords = 0;
    
    // 数据操作方法
    void loadOrderData();
    void updateOrderTable(const QJsonArray& orders);
    void updatePageButtons();
    void calculateTotalPages();
    void updateStatistics();
    
    // 搜索和过滤
    void searchOrders(const QString &keyword, const QString &status, const QString &dateFilter, const QString &ticketType);
    
    // 数据操作
    void refreshData();
    bool saveOrderData();
    void saveAndRefreshData();
    
    // API回调处理
    void onOrdersLoaded(bool success, const QJsonObject& response, const QString& errorMsg, int statusCode);
    void onOrderSaved(bool success, const QJsonObject& response, const QString& errorMsg, int statusCode);
    
    // 连接信号槽
    void setupConnections();
    
    // 订单操作
    void onViewOrderClicked(const QString& orderId);
    void onRefundOrderClicked(const QString& orderId);
    void onDeleteOrderClicked(const QString& orderId);
};

#endif // OPERATIONS_ORDER_H
